package com.cloudsigns.factorymanager2.produce.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.BaseActivity;
import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.engineering.bean.AccountInfoBean;
import com.cloudsigns.factorymanager2.produce.adapter.ProduceAttendanceListAdapter;
import com.cloudsigns.factorymanager2.produce.iview.IGetAccountListView;
import com.cloudsigns.factorymanager2.produce.presenter.GetAccountListPresenter;

import java.util.List;

public class ProduceAttendanceListActivity extends BaseActivity implements IGetAccountListView {
    private RelativeLayout rl_back;
    private TextView tv_title;
    private View rl_progressbar;
    private GridView gridView;

    private List<AccountInfoBean> accountItemList;
    private GetAccountListPresenter getAccountListPresenter;
    private ProduceAttendanceListAdapter adapter;

    @Override
    protected void onBaseCreate(Bundle savedInstanceState) {
        setContentView(R.layout.layout_produce_attendance_list);
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        rl_back = findViewById(R.id.rl_back);
        tv_title = findViewById(R.id.tv_title);
        rl_progressbar = findViewById(R.id.rl_progressbar);
        gridView = findViewById(R.id.gridView);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        tv_title.setText(getResources().getString(R.string.configuration_personnel));

        adapter = new ProduceAttendanceListAdapter(this);
        getAccountListPresenter = new GetAccountListPresenter(this);
        getAccountListPresenter.getAccountList();
    }

    @Override
    public void setListener() {
        rl_back.setOnClickListener(this);

        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long l) {
                AccountInfoBean accountInfoBean = accountItemList.get(position);
                Intent intent = new Intent(ProduceAttendanceListActivity.this, ProduceAttendanceActivity.class);
                intent.putExtra("avatarUrl", accountInfoBean.getAvatar());
                intent.putExtra("accountName", accountInfoBean.getAccountName());
                startActivity(intent);
            }
        });
    }

    @Override
    public void widgetClick(View view) {
        Intent mIntent;
        switch (view.getId()) {
            case R.id.rl_back:
                finish();
                break;
        }
    }

    @Override
    public void getAccountListSuccessed(List<AccountInfoBean> accountItemList) {
        if (null != accountItemList) {
            this.accountItemList = accountItemList;
            adapter.setData(accountItemList);
            gridView.setAdapter(adapter);
        }
    }

    @Override
    public void getAccountListFailed(final String desc) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                showToast(desc);
            }
        });
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }
}
